# apriori_calculator.py
import pandas as pd
from apriori import calcu_apriori

def compute_and_save_apriori(min_support=0.01, savefile="apriori.bin"):
    # 加载数据
    dataset = pd.read_csv("招聘数据集(含技能列表）.csv")

    # 将 skill_list 列转换为二维列表
    skill_list = []
    for skills in dataset['skill_list']:
        if pd.isna(skills):
            skill_list.append([])
        else:
            skill_list.append([s.strip().lower() for s in skills.split(',')])

    # 计算关联规则
    single, biga = calcu_apriori(skill_list, support=min_support, savefile=savefile)

    # 打印部分结果以供检查
    print("频繁项集示例:")
    print(single[:5])  # 打印前5个频繁单项集
    print("\n频繁项支持度示例:")
    print(biga[:5])  # 打印前5个频繁多项集

if __name__ == "__main__":
    # 定义支持度（根据数据集情况调整）
    support_threshold = 0.01  # 调整支持度阈值
    # 计算并保存关联规则
    compute_and_save_apriori(min_support=support_threshold)